import { createRouter, createWebHistory, createWebHashHistory } from 'vue-router'
import cookie from 'js-cookie'

const routes = [
    {
        path: '/',
        name: 'index',
        component: () => import('../components/home.vue'),
        // 独享路由守卫
        beforeEnter: (async (to, from) => {
            // let Auth = cookie.get('Auth')
            // console.log('from router/index.js', Auth)
            // if (!Auth && to.name !== 'login') {
            //     return { name: 'login' }
            // }
        })
    }, 
    {
        path: '/productSort',
        name: 'productSort',
        component: () => import('../components/productSort.vue')
    },
    {
        path: '/cart',
        name: 'cart',
        component: () => import('../components/cart.vue')
    },
    {
        path: '/personal',
        name: 'personal',
        component: () => import('../components/personal.vue')
    },
    {
        path: '/productDetail',
        name: 'productDetail',
        component: () => import('../components/productDetail.vue')
    },
    {
        path: '/comment',
        name: 'comment',
        component: () => import('../components/comment.vue')
    },
    {
        path: '/myComment',
        name: 'myComment',
        component: () => import('../components/myComment.vue')
    },
    {
        path: '/addComment',
        name: 'addComment',
        component: () => import('../components/addComment.vue')
    },
    {
        path: '/orderMaster',
        name: 'orderMaster',
        component: () => import('../components/orderMaster.vue')
    },
    {
        path: '/orderDetail',
        name: 'orderDetail',
        component: () => import('../components/orderDetail.vue')
    },
    {
        path: '/manage',
        name: 'manage',
        component: () => import('../components/manage.vue')
    },
    {
        path: '/demo',
        name: 'demo',
        component: () => import('../components/demo.vue')
    },
    {
        path: '/excelDetail',
        name: 'excelDetail',
        component: () => import('../components/excelDetail.vue')
    },
    {
        path: '/saveInfo',
        name: 'saveInfo',
        component: () => import('../components/saveInfo.vue')
    },
    {
        path: '/sendOrder',
        name: 'sendOrder',
        component: () => import('../components/sendOrder.vue')
    },
    {
        path: '/search',
        name: 'search',
        component: () => import('../components/search.vue')
    },
    {
        path: '/searchList',
        name: 'searchList',
        component: () => import('../components/searchList.vue')
    },
    {
        path: '/shopDetail',
        name: 'shopDetail',
        component: () => import('../components/shopDetail.vue')
    },
    {
        path: '/p2pChat',
        name: 'p2pChat',
        component: () => import('../components/p2pChat.vue')
    },
    {
        path: '/groupChat',
        name: 'groupChat',
        component: () => import('../components/groupChat.vue')
    },
    {
        path: '/friend',
        name: 'friend',
        component: () => import('../components/friend.vue')
    },
    {
        path: '/friendGroup',
        name: 'friendGroup',
        component: () => import('../components/friendGroup.vue')
    },
    {
        path: '/message',
        name: 'message',
        component: () => import('../components/message.vue')
    },
    {
        path: '/addressList',
        name: 'addressList',
        component: () => import('../components/addressList.vue')
    },
    {
        path: '/addressEdit',
        name: 'addressEdit',
        component: () => import('../components/addressEdit.vue')
    },
    {
        path: '/addFriend',
        name: 'addFriend',
        component: () => import('../components/addFriend.vue')
    },
    {
        path: '/login',
        name: 'login',
        component: () => import('../components/login.vue')
    },
    {
        path: '/balance',
        name: 'balance',
        component: () => import('../components/balance.vue')
    },
    {
        path: '/personalPlush',
        name: 'personalPlush',
        component: () => import('../view/personal/personal.vue')
    },
    {
        path: '/livingRoom',
        name: 'livingRoom',
        component: () => import('../view/livingRoom/livingRoom.vue')
    },
    {
        path: '/pkLivingRoom',
        name: 'pkLivingRoom',
        component: () => import('../view/pkLivingRoom/pkLivingRoom.vue')
    },
    {
        path: '/livingRoomList',
        name: 'livingRoomList',
        component: () => import('../view/livingRoomList/livingRoomList.vue')
    },
    {
        path: '/:pathMatch(.*)',
        component: () => import('../components/home.vue')
    }
]

const router = createRouter({
    history: createWebHashHistory(),
    routes
})

// 全局前置路由守卫
router.beforeEach(async (to, from) => {})

export default router
